package com.fantastic.web.controller.admin;

import com.fantastic.common.exception.enums.RespStatusInfo;
import com.fantastic.common.result.ResultData;
import com.fantastic.model.pojo.zjs.Spec;
import com.fantastic.service.zjs.SpecService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author: rxx
 * @since: 2024/5/31 10:29
 * @description: 菜品规格信息控制器
 */
@RestController
@RequestMapping("/spec")
public class SpecControllerAdmin {

    @Resource
    private SpecService specService;

    /**
     * 查询菜品规格信息
     *
     * @param spec
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("/listSpec")
    public ResultData listSpec(Spec spec,
                               @RequestParam(name = "page",
                                       defaultValue = "1") int pageNum,
                               @RequestParam(name = "limit", defaultValue = "9999999") int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Spec> specs = specService.listSpec(spec);
        PageInfo<Spec> pageInfo = new PageInfo<>(specs);
        return new ResultData(RespStatusInfo.OK, pageInfo);
    }

    /**
     * 查询单个菜品规格信息
     *
     * @param specId 菜品规格信息id
     * @return
     */
    @GetMapping("/getSpec")
    public ResultData getSpec(Integer specId) {
        return new ResultData(RespStatusInfo.OK, specService.getSpec(specId));
    }

    /**
     * 添加菜品规格信息
     *
     * @param spec 菜品规格信息对象
     * @return
     */
    @PostMapping("/insertSpec")
    public ResultData insertSpec(MultipartFile specFile, Spec spec) {
        return new ResultData(RespStatusInfo.OK, specService.insertSpec(specFile, spec));
    }

    /**
     * 修改菜品规格信息
     *
     * @param spec
     * @return
     */
    @PostMapping("/updateSpec")
    public ResultData updateSpec(MultipartFile specFile, Spec spec) {
        return new ResultData(RespStatusInfo.OK, specService.updateSpec(specFile, spec));
    }

    /**
     * 删除菜品规格信息
     *
     * @param specId
     * @return
     */
    @PostMapping("/deleteSpec")
    public ResultData deleteSpec(Integer specId) {
        return new ResultData(RespStatusInfo.OK, specService.deleteSpec(specId));
    }

}
